/**
 * 广寒宫
 * 网址:www.guanghangong.xyz
 */
package com.moon.admin.login;

import java.util.Date;
import java.util.List;

import com.moon.admin.sys.entity.SysUserEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.moon.admin.framework.secure.domain.AuthInfo;
import org.apache.ibatis.annotations.Update;

/**
 * 认证dao
 * @author ninglong
 */
@Mapper
public interface LoginMapper{

	@Select("select id from sys_user where status=0 and deleted=0 and password=#{password} and phoneNumber=#{account} limit 1")
	public SysUserEntity getUserIdByAccount(@Param("account")String account, @Param("password")String password);
	
	@Select("SELECT up.userId as id,u.userName,u.avatar,u.phoneNumber,u.sex,d.id as deptId,d.deptName,d.deptCode,p.id as postId,p.postName,p.postCode from sys_post p" + 
			" left join sys_user_post up on(p.id=up.postId)" + 
			" left join sys_dept d on(p.deptId=d.id)" + 
			" left join sys_user u on(u.id=up.userId)" + 
			" where up.userId=#{userId} and u.status=0 and up.primaryed=1 limit 1")
	AuthInfo getAuthInfoByUserId(Integer userId);


	@Select("SELECT r.roleCode from sys_role r LEFT JOIN sys_user_role ur on (r.id=ur.roleId) WHERE ur.userId=#{userId}")
	List<String> getRoleCodesByUserId(Integer userId);

	@Update("update sys_user set lastLoginTime=#{date} where id=#{userId}")
	void updateUserLastLoginTime(@Param("userId") Integer userId, @Param("date") Date date);
}
